
             
/**
 * 
 *
 * @File name:  TDepartmentDao.java 
 * @Create on:  2011-10-30 19:25:202
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
package com.boho.estates.check.dao;

            
import java.sql.Connection;
import java.util.List;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
            
        /**
 * 【盘盈盘亏信息:T_CHECK_INFO_DETAIL】的Dao操作类
 * 
 */
public class AdjustDao extends DAO {

	public static DynaBeanMap getCheckStatus(Connection con, String checkNo) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select CHAGE_STATUS from T_CHECK_INFO where IS_VALID = 1 and CHECK_NO = ?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMap("T_CHECK_INFO", con);
	}
	
	/**
	* 分页查询所有【盘亏信息:T_CHECK_INFO_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static List queryPKList(Connection con, String checkNo, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_CHECK_INFO_DETAIL where IS_CHECK = 0 and IS_VALID = 1 and CHECK_NO = ?");
		sql.append(" and DEPARTMENT_NAME in ("+ departIds +") ");
		sql.append(" order by BARCODE");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_CHECK_INFO_DETAIL", con);
	}
	
	/**
	* 分页查询所有【盘亏信息:T_CHECK_INFO_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-10-30
	* @author 陈伟
	*
	*/
	public static List queryPYList(Connection con, String checkNo, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS_DETAIL where CREATE_DATE > ");
		sql.append("(select CREATE_DATE from T_CHECK_INFO where IS_VALID = 1 and CHECK_NO = ?) ");
		sql.append(" and FA_STATUS not in('5','6') ");
		sql.append(" and DEPARTMENT_NO in ("+ departIds +") ");
		sql.append(" order by BARCODE");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_CHECK_INFO_DETAIL", con);
	}
	
	public static DynaBeanMap getPKSum(Connection con, String checkNo, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select sum(STOCK_PRICE) PK_COUNT from T_FIXED_ASSETS_DETAIL where BARCODE in(");
		sql.append("select BARCODE from T_CHECK_INFO_DETAIL where IS_CHECK = 0 and IS_VALID = 1 and CHECK_NO = ? and DEPARTMENT_NAME in ("+ departIds +"))");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMap("T_CHECK_INFO_DETAIL", con);
	}
	
	public static DynaBeanMap getPYSum(Connection con, String checkNo, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select sum(STOCK_PRICE) PY_COUNT from T_FIXED_ASSETS_DETAIL where CREATE_DATE > ");
		sql.append("(select CREATE_DATE from T_CHECK_INFO where IS_VALID = 1 and CHECK_NO = ?) ");
		sql.append(" and FA_STATUS not in('5','6') ");
		sql.append(" and DEPARTMENT_NO in ("+ departIds +") ");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMap("T_CHECK_INFO_DETAIL", con);
	}
	
	public static List queryCheckInfoByCheckNo(Connection con, String checkNo)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select BARCODE, STOCK_PRICE from T_CHECK_INFO_DETAIL where IS_VALID = 1 and IS_CHECK = 0 and CHECK_NO = ?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, checkNo);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_CHECK_INFO_DETAIL", con);
	}
	
	public static List queryAssetsList(Connection con, String ids) throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_FIXED_ASSETS_DETAIL where IS_VALID = 1 and id in(?)");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, ids);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_FIXED_ASSETS_DETAIL", con);
	}
	
}
